package cn.mihoyo.org.service.impl;

import cn.mihoyo.basic.util.PageList;
import cn.mihoyo.org.domain.Department;
import cn.mihoyo.org.mapper.DepartmentMapper;
import cn.mihoyo.org.query.DepartmentQuery;
import cn.mihoyo.org.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

public class IDepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public void add(Department department) {
        departmentMapper.add(department);
    }

    @Override
    public void delete(Long id) {
        departmentMapper.delete(id);
    }

    @Override
    public void update(Department department) {
        departmentMapper.update(department);
    }

    @Override
    public List<Department> findAll() {
        return departmentMapper.findAll();
    }

    @Override
    public Department findById(Long id) {
        return departmentMapper.findById(id);
    }

    @Override
    public PageList<Department> queryByPage(DepartmentQuery query) {
        Integer totals = departmentMapper.queryByCount(query);
        if (totals == null||totals == 0){
            return  new PageList<>(0,new ArrayList<>());
        }
        List<Department> departments = departmentMapper.queryByPage(query);
        return new PageList<>(totals,departments);
    }



}
